from mitmproxy import http
from mitmproxy.tools.main import mitmdump


class MyLocal:

    def request(self, flow: http.HTTPFlow):

        if "https://stock.xueqiu.com/v5/stock/batch/quote.json?_t=" in flow.request.pretty_url\
                and 'x=' in flow.request.pretty_url:

            # 将本地文件内容作为响应返回给客户端
           with open('stock.json', encoding='utf-8') as file:
               flow.response = http.HTTPResponse.make(
                   200, file.read()
               )


addons = [
    MyLocal()
]


if __name__ == '__main__':
    mitmdump(['-p', '8080', '-s', __file__])
